//===================================
//File: Image.cpp
//image functions
//Name: Smirnova O.P.
//Date: 02.04.12, v.1.0
//===================================

#include "Image.h"


unsigned int Image::count=0;
unsigned int Image::count_all=0;

using namespace std;

Image::Image(Body body,Throat throat)
	:body(body),
    throat(throat)
{
	count_all++;
    id=count_all;
	count++;
    //cout <<endl
	//<<"\nImage() ";
   // cout <<" id=" <<id<<":\n";
	List<Point> *p = new List<Point>(NULL);
	
	p->addElemToEnd(body.getTrapeze().getPointA());
	p->addElemToEnd(body.getTrapeze().getPointB());
	p->addElemToEnd(body.getTrapeze().getPointC());
	p->addElemToEnd(body.getTrapeze().getPointD());
	p->addElemToEnd(throat.getRect().getPointE());
	p->addElemToEnd(throat.getRect().getPointF());
	p->addElemToEnd(throat.getDistance().getPointE1());
	p->addElemToEnd(throat.getDistance().getPointF1());
	points=p;
    
//	cout <<" id=" <<id<<endl
 //   <<" Image."<<endl;
};

Image::~Image()
{
	//cout << "\n~Image:\n";
	//points->deleteList();
//	cout << "~Image\n";
	
};


void Image::moveTo(const Point p)
{
	Point el = body.getTrapeze().getPointC();
	Point pt = p;
	float dx = pt.getX()-el.getX();
	float dy = pt.getY()-el.getY();
	Elem<Point> *temp = points->getHead();
	Elem<Point> *head = points->getHead();
	do
	  {
		el = temp->getValue();
		el.moveTodXdY(dx,dy);
		temp->setValue(el);
		temp = temp->getNext();
	  }while(head!=temp);

};


void Image::moveTodXdY(const double x, const double y)
{
	Point el;
	body.moveTodXdY(x,y);
	throat.moveTodXdY(x,y);
	Elem<Point>* temp = points->getHead();
	
	Elem<Point> *head = points->getHead();
	do
	  {
		el = temp->getValue();
		el.moveTodXdY(x,y);
		temp->setValue(el);
		temp = temp->getNext();
	  }while(head!=temp);
};

void Image::consSF (const Point p)
{
	Point el;
	body.consSF(p);
	throat.consSF(p);
	Elem<Point>* temp = points->getHead();
	
	Elem<Point> *head = points->getHead();
	do
	  {
		el = temp->getValue();
		Point pt = p;
		el.consSP(pt);
		temp->setValue(pt);
		temp = temp->getNext();
	  }while(head!=temp);
};

List<Point> *Image::getPoints() const
{
	return points;
};

Body Image::getBody() const
{
	return body;
};


Throat Image::getThroat()const
{
	return throat;
};




const unsigned int Image::getID()
{
  return id;
};

unsigned int Image::countObject()
{
  return count; 
};
ostream& operator << (ostream& os, const Image& image)
{
	cout << "Image with id = "<<image.id ;
	//double h,d,a,r;
	Point P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11;
	Body body = image.getBody();
	Throat throat = image.getThroat();
	cout<<"Height of Trapeze: "<<body.getTrapeze().getH()<<endl;
	cout<<"Biggest part of Body "<<body.getTrapeze().getC()<<endl;
	cout<<"Small part of Body  "<<body.getTrapeze().getB()<<endl;
	cout<<"List of points:";
	//List<Point> *list=;
	image.getPoints()->writeList();
  return os;
}

int Image::operator>(int e)
{

	if(this->body.getTrapeze().getH()>5) return 1;
		else return 0;
	
}
